package com.ericom.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
@Entity
@Table(name="return_goods_order")
public class ReturnGoodsOrder extends BaseObject {
	@OneToMany(mappedBy="returnGoodsOrder",cascade=CascadeType.ALL,fetch=FetchType.LAZY,targetEntity=ReturnGoodsOrderItem.class)
	public Set<ReturnGoodsOrderItem> getReturnGoodsOrderItems() {
		return returnGoodsOrderItems;
	}

	public void setReturnGoodsOrderItems(
			Set<ReturnGoodsOrderItem> returnGoodsOrderItems) {
		this.returnGoodsOrderItems = returnGoodsOrderItems;
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this).append("id", id)
				.append("order", order).append("returnDate", returnDate)
				.append("returnAddress", returnAddress).toString();
	}

	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof ReturnGoodsOrder))
			return false;
		ReturnGoodsOrder castOther = (ReturnGoodsOrder) other;
		return new EqualsBuilder().append(id, castOther.id).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(id).toHashCode();
	}

	private Long id;
	private Order order;
	private String returnDate;
	private OrderDeliveryAddress returnAddress;
	private Set<ReturnGoodsOrderItem> returnGoodsOrderItems=new HashSet<ReturnGoodsOrderItem>();
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	@ManyToOne(cascade={CascadeType.MERGE})
	@JoinColumn(name="order_id")
	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}
    @Column(name="return_date")
	public String getReturnDate() {
		return returnDate;
	}

	public void setReturnDate(String returnDate) {
		this.returnDate = returnDate;
	}
	@OneToOne(optional = false, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "adddress_id")
	public OrderDeliveryAddress getReturnAddress() {
		return returnAddress;
	}

	public void setReturnAddress(OrderDeliveryAddress returnAddress) {
		this.returnAddress = returnAddress;
	}
}
